/**
 * 20080121 0927: Eric Kao, modify comment<br>
 * 20080118 1744: Eric Kao was created.<br>
 */

package query.hql;

import java.util.Iterator;
import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;

import com.e885.hibernate.HibernateSessionFactory;
import com.e885.log.E885Logger;

/**
 * 測試取得二個屬性的 HQL Query<br>
 * 使用 "select bean.id, bean.name from PersonInfo as bean" 方式時， 當<br>
 * query.list() 傳回來的 List, 和只使用 from PersonInfo 是不一樣的(指 List 裏面的物件)<br>
 * 1. 使用 "from PersonInfo": 是傳 PersonInfo 整個物件的 List<br>
 * 2. 使用 "select bean.name from PersonInfo as bean" 是傳字串物件回來<br>
 * 3. 使用 "select bean.id, bean.name from PersonInfo as bean" 是傳物件陣列回來<br>
 * <br>
 * Copyright: Copyright (c) 2001-2008<br>
 * Company: E885 Group
 * 
 * @author Eric.Kao(gau168.gau@msa.hinet.net)
 * @version 1.0
 */
public class HQLAttributes
{
	/**
	 * @param args
	 */
	public static void main( String[] args )
	{
		new HQLAttributes();
	}

	@SuppressWarnings( "unchecked" )
	public HQLAttributes()
	{
		Session session = HibernateSessionFactory.getSession();

		Query query = session.createQuery( "select bean.id, bean.name from PersonInfo as bean" );

		List< Object[] > list = query.list();

		Iterator< Object[] > iterator = list.iterator();

		while( iterator.hasNext() )
		{
			Object str[] = iterator.next();
			E885Logger.testLog.debug( "=========================" );
			E885Logger.testLog.debug( "id:" + str[ 0 ] );
			E885Logger.testLog.debug( "name:" + str[ 1 ] );
		}

		E885Logger.testLog.debug( "All row:" + list.size() );

		HibernateSessionFactory.closeSession();
	}

}
